package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TaskAlert;
import com.ruoyi.system.service.ITaskAlertService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 个人计划Controller
 * 
 * @author pluto_xun@qq.com
 * @date 2020-12-11
 */
@Controller
@RequestMapping("/zzb/taskalert")
public class TaskAlertController extends BaseController
{
    private String prefix = "zzb/taskalert";

    @Autowired
    private ITaskAlertService taskAlertService;

    @RequiresPermissions("zzb:taskalert:view")
    @GetMapping()
    public String taskalert()
    {
        return prefix + "/taskalert";
    }

    /**
     * 查询个人计划列表
     */
    @RequiresPermissions("zzb:taskalert:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskAlert taskAlert)
    {
        startPage();
        List<TaskAlert> list = taskAlertService.selectTaskAlertList(taskAlert);
        return getDataTable(list);
    }

    /**
     * 导出个人计划列表
     */
    @RequiresPermissions("zzb:taskalert:export")
    @Log(title = "个人计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TaskAlert taskAlert)
    {
        List<TaskAlert> list = taskAlertService.selectTaskAlertList(taskAlert);
        ExcelUtil<TaskAlert> util = new ExcelUtil<TaskAlert>(TaskAlert.class);
        return util.exportExcel(list, "taskalert");
    }

    /**
     * 新增个人计划
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存个人计划
     */
    @RequiresPermissions("zzb:taskalert:add")
    @Log(title = "个人计划", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TaskAlert taskAlert)
    {
        return toAjax(taskAlertService.insertTaskAlert(taskAlert));
    }

    /**
     * 修改个人计划
     */
    @GetMapping("/edit/{alertId}")
    public String edit(@PathVariable("alertId") Long alertId, ModelMap mmap)
    {
        TaskAlert taskAlert = taskAlertService.selectTaskAlertById(alertId);
        mmap.put("taskAlert", taskAlert);
        return prefix + "/edit";
    }

    /**
     * 修改保存个人计划
     */
    @RequiresPermissions("zzb:taskalert:edit")
    @Log(title = "个人计划", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TaskAlert taskAlert)
    {
        return toAjax(taskAlertService.updateTaskAlert(taskAlert));
    }

    /**
     * 删除个人计划
     */
    @RequiresPermissions("zzb:taskalert:remove")
    @Log(title = "个人计划", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(taskAlertService.deleteTaskAlertByIds(ids));
    }
}
